package com.deyang.mycommon.ui.activity.study;


import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.deyang.mycommon.R;
import com.deyang.mycommon.adapter.TestBaseAdapter;
import com.deyang.mycommon.mvp.presenter.BaseAdapterPresenter;
import com.deyang.mycommon.mvp.view.BaseAdapterView;
import com.deyang.mycommon.ui.baseui.BaseActivity;
import com.deyang.mycommon.util.ViewUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BaseAdapterActivity extends BaseActivity implements BaseAdapterView {


    @BindView(R.id.rv_test)
    RecyclerView rvTest;

    private TestBaseAdapter baseAdapter;

    private int currentPage = 0, maxPage = 2;

    private BaseAdapterPresenter baseAdapterPresenter;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_base_adapter);
        ButterKnife.bind(this);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        baseAdapterPresenter = new BaseAdapterPresenter(this,
                this);

        baseAdapter = new TestBaseAdapter(this, baseAdapterPresenter.getAdapterData());
        ViewUtil.initRecycleView(this, true, rvTest, baseAdapter);

        baseAdapterPresenter.initData();
    }


    @Override
    public void setListener() {
        super.setListener();
        baseAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.iv_del:
                        break;
                }
            }
        });

        baseAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });

        /*
        baseAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                //sw.setEnabled(false);//上拉加载的时候关闭下拉刷新 之后再打开

                new Thread() {
                    @Override
                    public void run() {
                        super.run();
                        try {
                            Thread.sleep(2000);
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (currentPage >= maxPage) {
                                        //加载结束
                                        baseAdapter.loadMoreEnd();

                                    } else {
                                        baseAdapter.addData(new BaseAdapterTestItem(getColorRes(R.color.toast_info), "上拉新数据：" + testItemList.size()));
                                        baseAdapter.addData(new BaseAdapterTestItem(getColorRes(R.color.toast_info), "上拉新数据：" + testItemList.size()));
                                        baseAdapter.addData(new BaseAdapterTestItem(getColorRes(R.color.toast_info), "上拉新数据：" + testItemList.size()));
                                        baseAdapter.addData(new BaseAdapterTestItem(getColorRes(R.color.toast_info), "上拉新数据：" + testItemList.size()));
                                        baseAdapter.addData(new BaseAdapterTestItem(getColorRes(R.color.toast_info), "上拉新数据：" + testItemList.size()));
                                        //加载完成
                                        baseAdapter.loadMoreComplete();
                                        //加载失败
                                        //baseAdapter.loadMoreFail();
                                    }
                                }
                            });
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }.start();

                currentPage++;

                //sw.setenable(true)
            }
        }, rvTest);
        */

    }

    @OnClick({
            R.id.btn_add,
    })
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_add:

                break;
        }
    }


    @Override
    public void refreshUpdateUI() {
        baseAdapter.notifyDataSetChanged();
    }

    @Override
    public void refreshErro(String erroMsg) {
        showToastError(erroMsg);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
